home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / DirectInput / DIConfig / iclassfact.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-27  |  1.8 KB  |  109 lines

  1. //-----------------------------------------------------------------------------
  2. // File: iclassfact.cpp
  3. //
  4. // Desc: Implements the class factory for the UI.
  5. //
  6. // Copyright (C) Microsoft Corporation. All Rights Reserved.
  7. //-----------------------------------------------------------------------------
  8.  
  9. #include "common.hpp"
  10.  
  11.  
  12. //QI
  13. STDMETHODIMP CFactory::QueryInterface(REFIID riid, LPVOID* ppv)
  14. {
  15.     //null the put parameter
  16.     *ppv = NULL;
  17.  
  18.     if ((riid == IID_IUnknown) || (riid == IID_IClassFactory))
  19.     {
  20.         *ppv = this;
  21.         AddRef();
  22.         return S_OK;
  23.     }
  24.  
  25.     return E_NOINTERFACE;
  26.  
  27. }
  28.  
  29.  
  30.  
  31. //AddRef
  32. STDMETHODIMP_(ULONG) CFactory::AddRef()
  33. {
  34.     return InterlockedIncrement(&m_cRef);
  35. }
  36.  
  37.  
  38. //Release
  39. STDMETHODIMP_(ULONG) CFactory::Release()
  40. {
  41.     LONG cRef;
  42.     
  43.     cRef = InterlockedDecrement(&m_cRef);
  44.     if (cRef == 0)
  45.     {
  46.         delete this;
  47.     }
  48.  
  49.     return cRef;
  50. }
  51.  
  52.  
  53. //CreateInstance
  54. STDMETHODIMP CFactory::CreateInstance(IUnknown* pUnkOuter, REFIID riid, LPVOID *ppv)
  55. {
  56.     HRESULT hr = S_OK;
  57.  
  58.     //can't aggregate
  59.     if (pUnkOuter != NULL)
  60.     {
  61.         return CLASS_E_NOAGGREGATION;
  62.     }
  63.  
  64.     //create component
  65.     CDirectInputActionFramework* pDIActionFramework = new CDirectInputActionFramework();
  66.     if (pDIActionFramework == NULL)
  67.     {
  68.         return E_OUTOFMEMORY;
  69.     }
  70.  
  71.     //get the requested interface
  72.     hr = pDIActionFramework->QueryInterface(riid, ppv);
  73.  
  74.     //release IUnknown
  75.     pDIActionFramework->Release();
  76.     return hr;
  77.  
  78. }
  79.  
  80.  
  81. //LockServer
  82. STDMETHODIMP CFactory::LockServer(BOOL bLock)
  83. {
  84.     HRESULT hr = S_OK;
  85.     if (bLock)
  86.     {
  87.         InterlockedIncrement(&g_cServerLocks);
  88.     }
  89.     else
  90.     {
  91.         InterlockedDecrement(&g_cServerLocks);
  92.     }
  93.  
  94.     return hr;
  95. }
  96.  
  97.  
  98. //constructor
  99. CFactory::CFactory()
  100. {
  101.     m_cRef = 1;
  102. }
  103.  
  104.  
  105. //destructor
  106. CFactory::~CFactory()
  107. {
  108. }
  109.